<template>
	<om-page :title="pageTitle">
		<om-menu :menuList="datas" colLen="5" :bordered="false" fontSize="small" @click="click"></om-menu>
	</om-page>
</template>

<script>
	export default {
		data() {
			return {
				pageTitle: "",
				datas: [],

			}
		},
		watch:{
			datas:{
				handler(newVal,oldVal){
					if(newVal.length){
						this.workHourCanConfirm()
						this.salarybillCanConfirm()
					}
				},
				deep:true
			}
		},
		methods: {
			salarybillCanConfirm(){
				let _that = this
				_that.om.request(
					"salaryBill/canConfirm"
				).then(res=>{
					for(let item of _that.datas ){
						if(item.h5url === "/pages/mine/salarybill/salarybill" ){
							_that.$set(item,"showDot",res.value)
						}
					}
				})
			},
			workHourCanConfirm() {
				let _that = this
				_that.om.request(
					"attendConfirm/canConfirm"
				).then(res=>{
					for(let item of _that.datas ){
						if(item.h5url === "/pages/mine/workhour/workhour"){
							_that.$set(item,"showDot",res.value)
						}
					}
				})
			},
			click(e) {
				let m = this.datas[e.index]
				if (m && m.code) {
					this.om.openHistoryPage(m.text, m.code)
				}
			}
		},
		onLoad(options) {
			let _that = this
			_that.pageTitle = (options.title || '') + '工具列表'
			uni.setNavigationBarTitle({
				title: _that.pageTitle
			});
			uni.getStorage({
				key: "sub-menu-list",
				success: function(res) {
					if (res.data) {
						res.data.map((item, i) => {
							if (item.attributes && item.attributes.isnew) {
								item.badgeText = '新'
								item.badgeType = 'success';
							}
						})
					}
					_that.datas = res.data
					uni.removeStorage({
						key: "sub-menu-list"
					})
				}
			})
		},
		onShow() {
			this.workHourCanConfirm()
			this.salarybillCanConfirm()
		}
	}
</script>

<style>

</style>
